package tech.yunland.shop.domain.dao;

import com.moyuer.bsf.domain.dao.BaseDao;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import tech.yunland.shop.domain.model.Goods;
import tech.yunland.shop.domain.model.Tag;
import tech.yunland.shop.domain.model.TagGoods;

import java.util.List;

/**
 * @author: 王东阳<350456985@qq.com>
 * 16/4/1
 */
@Repository
public class TagGoodsDao extends BaseDao<TagGoods, String>{

	public TagGoods getTGID(Tag tag, Goods goods) {
		TagGoods result = null;

		DetachedCriteria criteria = DetachedCriteria.forClass(TagGoods.class);
        criteria.add(Restrictions.eq("tag.id", tag.getId()));
        criteria.add(Restrictions.eq("goods.id", goods.getId()));

        List<TagGoods> tgs = this.findByCriteria(criteria);

        if (tgs.size() == 0) {
			return result;
		}else {
			result = tgs.get(0);
		}

		return result;
	}
}
